/** 字符串开始  **/
{
    let [a, b, c, d, e] = "HelloWorld"
    console.log('a:', a);   // H
    console.log('b:', b);   // e
    console.log('c:', c);   // l
    console.log('d:', d);   // l
    console.log('e:', e);   // o
    console.log("-----------------------------------------------")
}
{
    let {a1: a, b1: b} = "HelloWorld"
    console.log('a1:', a);   // undefined

    let {c, d, e} = "HelloWorld"
    console.log('c:', c);   // undefined
    console.log("-----------------------------------------------")
}
{
    let {a1: a, b1: b} = "HelloWorld"
    console.log('a1:', a);   // undefined

    let {c, d, e} = "HelloWorld"
    console.log('c:', c);   // undefined
    console.log("-----------------------------------------------")
}
{
    let {length: len} = 'Hello';
    console.log(len);  //5
    console.log("----------------------字符串结束-------------------------")
}

/** 字符串结束  **/
/** 数字/布尔值 开始  **/
{
    console.log("----------------------数字/布尔值 开始-------------------------")  
    let {Num:  s} = 123;
    console.log( s === Number.prototype.Num)   //true
    let {Num:  y} = true;
    console.log( y === Boolean.prototype.Num)   //true
}
{
   // let {Num: m} = undefined;
   // let {Num: n} = null;
   // Cannot match against 'undefined' or 'null'.
}
/** 数字/布尔值 结束  **/
/** 函数参数解构赋值 开始  **/
{
    console.log('----------------- 函数参数解构赋值 开始 -----------------')
    function funTets([x = 10, y = 20]){
        console.log('x:'+ x, "y:"+ y)
    }
    funTets([2, 4]);  // x:2  y:4
    funTets([ , 4]);  // x:10 y:4
    funTets([6,  ]);  // x:6  y:20
    funTets([]);      // x:10 y:20
//  funTets();        //TypeError: Cannot read property 'Symbol(Symbol.iterator)' of undefined
console.log('----------------------------------')
}

{
    let arr = [[1, 3],[4, 9],[10,20]];
    arr.map((a) => {console.log(a)});
    //  [ 1, 3 ]
    //  [ 4, 9 ]
    //  [ 10, 20 ]
    arr.map(([x, y]) => {console.log('x:'+ x, 'y:'+y)});
    //  x:1 y:3
    //  x:4 y:9
    //  x:10 y:20

    console.log('--------------map遍历结束--------------------')
}
{
    function textObject({x=0, y=0}){
        console.log("x:"+x, ", y:"+y);
    }

    textObject({x: 20, y: 10});  //x:20 y:10
    textObject({x: 20});         //x:20 y:0
    textObject({y: 10});         //x:0 y:10
    textObject({});              //x:0 y:0
//  textObject();                //Cannot match against 'undefined' or 'null'.
console.log('---------------传入object结束-------------------')
}

{
    let funTest = ({x, y} = {x: -1, y: -1}) => { console.log( "x:"+x+", y:"+y) }
    funTest({x: 10, y: 20});   // x:10 y:20
    funTest({x: 10});          // x:10 y:undefined
    funTest({y: 20});          // x:undefined y:20
    funTest({});               // x:undefined y:undefined
    funTest();                 // x:-1 y:-1
    console.log('---------------为参数指定默认值-------------------')
}
{
    let funTest = ({x=-1, y=-1} = {}) => {console.log("x:"+x+", y:"+y)}
    funTest({x: 10, y: 20});   // x:10 y:20
    funTest({x: 10});          // x:10 y:-1
    funTest({y: 20});          // x:-1 y:20
    funTest({});               // x:-1 y:-1
    funTest();                 // x:-1 y:-1
}
{
    ['Hello', undefined, 'World', null].map((x = '空') => { console.log(x)} )
    // Hello
    // 空
    // World
    // null
    console.log('---------------参数为undefined-------------------')
}
{
//  let [(a)] = [10];  // Unexpected token (
//  let {a, b, (c)} = {a: 1, b: 2, c: 3};  //Unexpected token (
//  let {(a: x)} = {a: 1}   //Unexpected token (
//  let ({a: x}) = {a: 1}   //let is not defined
//  let {a: ({b: c})} = {x: {b: 1}}  //Unexpected token (
}

{
//  function fun([(x)]) { return x; }  //Unexpected token (
//  function fun([x,(y)]) { return x; }  //Unexpected token (
}
{
    [{x: a},{y: b}] = [{x: 10}, {y: 20}]
    console.log("a:"+a, ", b:"+b);  //a:10 , b:20
//  [{x1: a1},({y1: b1})] = [{x1: 10}, {y1: 20}]
//  console.log("a1:"+a1, ", b1:"+b1);  //Unexpected token (
    console.log('---------------赋值语句模式使用小括号报错的情况-------------------')
}

{
    [(a)] = [3];   //3
    console.log(a);
    ({a: {b: (x)}} = {a:{b: 3}})
    console.log(a, b, x);  // 3 20 3
    [(parseInt.prop)] = [3];
    console.log(parseInt, parseInt.prop)  //{ [Function: parseInt] prop: 3 } 3
}
{
    let a =1;
    let b =2;
    [a, b] = [b, a]
    console.log(a, b);  //2 1
}
{
    function fun(){
        return [10, 20, 30, 40]
    }
    let [a, b, c, d] = fun();
    console.log(a, b, c, d) // 10 20 30 40
}
{
    function fun1(){
        return {
            x: "Hello",
            y: "World"
        }
    }
    let {x, y} = fun1();
    console.log(x, y);   // Hello World
}
{
    let x1 = ([a, b, c, d]) => {console.log(a, b, c, d);}
    x1([10, 20, 30, 40]);  //10 20 30 40
    let x2 = ({a, b, c, d}) => {console.log(a, b, c, d);}
    x2({a: 1, b: 2, c: 3, d: 4});  //1 2 3 4
}
{
    let json = {
        a: 100, 
        b: 200,
        c: 300
    }
    let {a, b, c, d='null Number'} = json;
    console.log(a, b, c, d); //100 200 300 'null Number'
}
{
    let fun1 = ([a = -1, b = -2, c = -3]) =>{ console.log(a, b, c)}
    fun1([10, 20]);      //10 20 -3
    fun1([10, , 30]);    //10 -2 30
    fun1([, 20, 30]);    //-1 20 30
    fun1([]);            //-1 -2 -3
//  fun1();              //Cannot read property 'Symbol(Symbol.iterator)' of undefined
}
